package com.metaverse.backend.service;

import com.metaverse.backend.domain.AppConfig;
import com.metaverse.backend.exception.BusinessException;
import com.metaverse.backend.repo.AppConfigRepo;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@AllArgsConstructor
@Slf4j
public class AppConfigService {

    private AppConfigRepo appConfigRepo;

    /**
     * 查找应用ID
     * @param appId
     * @return
     */
    public AppConfig findByAppId(String appId){
        return appConfigRepo.findByAppId(appId);
    }


    /**
     * 获取应用配置
     * @param appId
     * @return
     */
    public AppConfig requiredAppConfig(String appId){
        AppConfig appConfig = findByAppId(appId);
        if(appConfig == null){
            log.error("应用未找到：" + appId);
            throw new BusinessException("应用未找到");
        }
        return appConfig;
    }


}
